package extensions;

import models.shop.path.ProductFilter;
import play.mvc.Scope;
import play.templates.JavaExtensions;

import java.util.HashMap;
import java.util.Map;

public class ParamsExtension extends JavaExtensions {
    public static Map<String, String> getParams(ProductFilter filter) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", String.valueOf(filter.categoryId));
        par.put("brandId", String.valueOf(filter.brandId));
        par.put("pageNumber", String.valueOf(filter.pageNumber));
        par.put("productId", String.valueOf(filter.productId));
        par.put("brandPage", String.valueOf(filter.brandPage));
        return par;
    }

    public static Map<String, String> resetBrand(Scope.Params params) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", String.valueOf(0));
        par.put("pageNumber", String.valueOf(1));
        par.put("produhttp://www.gerasoft.com/english.htmlctId", String.valueOf(0));
        par.put("brandPage", params.get("brandPage") == null ? String.valueOf(1) : params.get("brandPage"));
        return par;
    }

    public static Map<String, String> getFilter(Scope.Params params, ProductFilter filter) {
        if (filter.productId > 0) {
            return getProductFilter(params, filter.productId);
        } else if (filter.pageNumber > 1) {
            return getPageNumberFilter(params, filter.pageNumber);
        } else if (filter.brandId > 0) {
            return getBrandFilter(params, filter.brandId);
        } else {
            return getCategoryFilter(params, filter.categoryId);
        }
    }

    public static Map<String, String> getCategoryFilter(Scope.Params params, int categoryId) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", String.valueOf(categoryId));
        par.put("brandId", params.get("brandId") == null ? String.valueOf(0) : params.get("brandId"));
        par.put("pageNumber", String.valueOf(1));
        par.put("productId", String.valueOf(0));
        par.put("brandPage", String.valueOf(1));
        return par;
    }

    public static Map<String, String> getBrandFilter(Scope.Params params, int brandId) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", String.valueOf(brandId));
        par.put("pageNumber", String.valueOf(1));
        par.put("productId", String.valueOf(0));
        par.put("brandPage", params.get("brandPage") == null ? String.valueOf(1) : params.get("brandPage"));
        return par;
    }

    public static Map<String, String> getBrandPageFilter(Scope.Params params, int brandPage) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", params.get("brandId") == null ? String.valueOf(0) : params.get("brandId"));
        par.put("pageNumber", String.valueOf(1));
        par.put("productId", String.valueOf(0));
        brandPage = brandPage < 1 ? 1 : brandPage;
        par.put("brandPage", String.valueOf(brandPage));
        return par;
    }

    public static Map<String, String> excludeBrandPage(Scope.Params params) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", params.get("brandId") == null ? String.valueOf(0) : params.get("brandId"));
        par.put("pageNumber", String.valueOf(1));
        par.put("productId", String.valueOf(0));
        return par;
    }
    public static Map<String, String> getProductFilter(Scope.Params params, int productId) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", params.get("brandId") == null ? String.valueOf(0) : params.get("brandId"));
        par.put("pageNumber", params.get("pageNumber") == null ? String.valueOf(1) : params.get("pageNumber"));
        par.put("productId", String.valueOf(productId));
        par.put("brandPage", params.get("brandPage") == null ? String.valueOf(1) : params.get("brandPage"));
        return par;
    }

    public static Map<String, String> getPageNumberFilter(Scope.Params params, long pageNumber) {
        Map<String, String> par = new HashMap<String, String>();
        par.put("categoryId", params.get("categoryId") == null ? String.valueOf(0) : params.get("categoryId"));
        par.put("brandId", params.get("brandId") == null ? String.valueOf(0) : params.get("brandId"));
        par.put("pageNumber", String.valueOf(pageNumber));
        par.put("productId", String.valueOf(0));
        par.put("brandPage", params.get("brandPage") == null ? String.valueOf(1) : params.get("brandPage"));
        return par;
    }
}
